import { defineStore } from 'pinia'

/**
 * 应用全局状态管理
 */
export const useAppStore = defineStore('app', {
  state: () => ({
    // 应用信息
    appVersion: '',
    
    // 侧边栏状态
    sidebarCollapsed: false,
    
    // 当前页面
    currentPage: 'home',
    
    // 加载状态
    loading: false,
    
    // 主题设置
    theme: 'light', // light | dark
    
    // 语言设置
    language: 'zh-CN',
    
    // 照片视图模式
    photoViewMode: 'grid', // grid | list | masonry
    
    // 网格列数
    gridColumns: 4,
    
    // 缩略图大小
    thumbnailSize: 200,
    
    // 照片排序
    photoSortBy: 'captured_at', // captured_at | created_at | file_name | file_size
    photoSortOrder: 'desc', // asc | desc
    
    // 照片筛选条件
    photoFilters: {
      search: '',
      dateFrom: null,
      dateTo: null,
      cameraMake: '',
      cameraModel: '',
      rating: null,
      tags: [],
      albums: []
    }
  }),
  
  getters: {
    // 获取应用信息
    appInfo: (state) => ({
      version: state.appVersion,
      theme: state.theme,
      language: state.language
    }),
    
    // 获取照片视图设置
    photoViewSettings: (state) => ({
      mode: state.photoViewMode,
      gridColumns: state.gridColumns,
      thumbnailSize: state.thumbnailSize,
      sortBy: state.photoSortBy,
      sortOrder: state.photoSortOrder
    }),
    
    // 获取当前筛选条件
    currentFilters: (state) => state.photoFilters
  },
  
  actions: {
    // 设置应用版本
    setAppVersion(version: string) {
      this.appVersion = version
    },
    
    // 切换侧边栏状态
    toggleSidebar() {
      this.sidebarCollapsed = !this.sidebarCollapsed
    },
    
    // 设置当前页面
    setCurrentPage(page: string) {
      this.currentPage = page
    },
    
    // 设置加载状态
    setLoading(loading: boolean) {
      this.loading = loading
    },
    
    // 设置主题
    setTheme(theme: string) {
      this.theme = theme
    },
    
    // 设置语言
    setLanguage(language: string) {
      this.language = language
    },
    
    // 设置照片视图模式
    setPhotoViewMode(mode: string) {
      this.photoViewMode = mode
    },
    
    // 设置网格列数
    setGridColumns(columns: number) {
      this.gridColumns = columns
    },
    
    // 设置缩略图大小
    setThumbnailSize(size: number) {
      this.thumbnailSize = size
    },
    
    // 设置照片排序
    setPhotoSort(sortBy: string, sortOrder: string) {
      this.photoSortBy = sortBy
      this.photoSortOrder = sortOrder
    },
    
    // 设置照片筛选条件
    setPhotoFilters(filters: any) {
      this.photoFilters = { ...filters }
    },
    
    // 重置照片筛选条件
    resetPhotoFilters() {
      this.photoFilters = {
        search: '',
        dateFrom: null,
        dateTo: null,
        cameraMake: '',
        cameraModel: '',
        rating: null,
        tags: [],
        albums: []
      }
    }
  }
})